Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ViscoElasticContacts #248

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

diegoferigo
Copy link
Member

@diegoferigo diegoferigo commented Sep 27, 2024

This PR implements a revised and ―possibly― improved contact model originally proposed in the following manuscript:

Exponential Integration for Efficient and Accurate Multi-Body Simulation with Stiff Viscoelastic Contacts
Hammoud, Olivieri, Righetti, Carpentier, Del Prete
https://arxiv.org/abs/2101.06846

Although the theory is not yet public, my implementation proposes the following improvements:

  1. The original formulation only considered linear contact models. If $\delta$ and $\dot{\delta}$ are the penetration depth and the penetration rate along the terrain's normal direction, the new formulation enables using any non-linear contact model belonging to the family of Hunt/Crossley models:
$$f^{\perp} = (K \delta^p) \, \delta + (D \delta^q) \, \dot{\delta}$$
  1. The new formulation allows to use non-linear contact models that intrinsically support uneven terrain, under the assumption that we can gather the terrain normal and the terrain height at any $x-y$ coordinate.
  2. The new formulation does not integrate the contact dynamics in terms of displacement w.r.t. the anchor point $\mathbf{x} = [\Delta \mathbf{p}; \, \Delta \dot{\mathbf{p}}],$ but it integrates the contact dynamics ignoring the anchor point entirely, therefore $\mathbf{x} = [\mathbf{p}; \, \dot{\mathbf{p}}].$ This enables to do not keep track of the location where the contact was made.
  3. The new formulation changes completely how the frictional component of the force (i.e., the tangential component) is computed. It moves the logic to compute the sticking tangential force inside the non-linear contact model, exploiting the fact that we can adopt AD to linearize the contact model with arbitrarily complex logic. The tangential displacement to obtain the $\Delta$ variables are computed by considering an additional state $\mathbf{m}$ of the terrain deformation (that, in a sense, replaces the need of keeping track of the contact creation). This workaround was inspired by the soft-contact model already implemented in the soft contacts of JaxSim. For this reason, the state of the contact dynamics becomes $\mathbf{x} = [\mathbf{p}; \, \dot{\mathbf{p}}; \, \mathbf{m}].$
  4. The introduction of $\mathbf{m}$ in the state of the contact dynamics allows us to integrate this variable in continuous time, obtaining a stable and precise computation of the contact forces.
  5. The new formulation, thanks to the presence of $\mathbf{m}$ in the state of the contact dynamics and the possibility to have arbitrarily complex non-linear contact models, completely changes the original implementation of sticking/slipping transition. I adapted the sticking/slipping logic used by the default soft contact model of JaxSim to this new contact model, and I obtained sound theoretical results (that also works well in practice, paying the price of a larger $A$ matrix used in $\exp^{At}$).
viscoelastic_contacts_ergocub.mp4

Open points left to future work:

  • The main bottleneck of the whole contact model is the computation of the matrix exponential. In the paper, the authors describe a custom implementation that might be considerably faster than jax.scipy.linalg.expm. However, beyond implementing the logic, which is doable, we should also figure out how to expose AD. It's not clear to me what could be the performance degradation of relying to pure AD w.r.t. the usage of the custom adjoints as done internally in JAX.
  • Exposing to the user the logic to enable/disable collidable points is not included in this PR. For the time being, altering directly the low-level boolean array is necessary for thinnin out the considered points.

📚 Documentation preview 📚: https://jaxsim--248.org.readthedocs.build//248/

@diegoferigo diegoferigo self-assigned this Sep 27, 2024
@diegoferigo diegoferigo changed the title Add new ViscoElasticContactModel Add new ViscoElasticContacts Sep 27, 2024
@xela-95
Copy link
Member

xela-95 commented Sep 30, 2024

Hi @diegoferigo, another early comment since I'm testing this contact model: in jaxsim.api.ode.system_dynamics @

case SoftContacts():
ode_state_kwargs["tangential_deformation"] = aux_dict["m_dot"]
case RigidContacts() | RelaxedRigidContacts():
pass
case _:
raise ValueError("Unable to determine contact state class prefix.")
# Extract the velocities.
we should add a case for this class of contact model.

From collidable_point_dynamics I can see this model outputs some auxiliary data, that should be extracted:

aux_data = dict(W_f_avg2_C=W_f̿_Ci, m_tf=m_tf)

@diegoferigo
Copy link
Member Author

[...]
we should add a case for this class of contact model.

From collidable_point_dynamics I can see this model outputs some auxiliary data, that should be extracted: [...]

Thanks @xela-95 for the feedback. The dictionary returned by the visco-elastic contact model is somewhat different then the one returned by the soft contact model. The latter returns $\dot{\mathbf{m}}$ (the derivative of the material deformation) that needs to be integrated together with the generalized state $(\mathbf{q}, \, \boldsymbol{\nu})$. The visco-elastic contacts, instead, directly compute $\mathbf{m}(t+\Delta t)$, therefore we need to override $\mathbf{m}$ of the extended state similarly than the velocity reset done in by the rigid contacts.

Regardless, I'm still unsure how to integrate the new visco-elastic contacts with the default jaxsim.model.step function. What I just wrote is only necessary when the default integrators are used. The best way to exploit this new contact model, however, is to use its own integrator jaxsim.rbda.contacts.visco_elastic.step, that integrates both the generalized position and velocity using the contact forces computed explicitly with the continuous exponential integrator.

@diegoferigo diegoferigo force-pushed the visco_elastic_contacts branch 3 times, most recently from aee7fc2 to d534a25 Compare October 7, 2024 16:19
@diegoferigo diegoferigo marked this pull request as ready for review October 7, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants